package com.vrv.vap.demo.service.impl;

import com.vrv.vap.oauth2.config.DefaultPasswordEncoderConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Import;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * @author wh1107066
 * @date 2021/6/24 19:12
 */
@Component("userDetailsService")
@Import(DefaultPasswordEncoderConfig.class)
public class UserDetailsServiceImpl implements UserDetailsService {
    @Autowired
    private PasswordEncoder passwordEncoder;
    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        String pwd = passwordEncoder.encode("123456");
        return new User("admin", pwd, true, true,
                true, true,
                AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER, ROLE_USER2"));
    }
}
